﻿@inherits FeedbackComponent<DrawerInput<int>, bool>

<Spin Spinning="_isLoading">
    <Row>
        <AntDesign.Col Span="24">
            <Tree @ref="_tree"
                  TItem="ResourceDto"
                  ShowLine
                  Checkable
                  DataSource="_resources"
                  KeyExpression="x=>x.DataItem.Id.ToString()"
                  TitleExpression="x=>GetFullName(x.DataItem)"
                  ChildrenExpression="x=>x.DataItem.Children?.ToList()"
                  IconExpression="x=>x.DataItem.Icon"
                  IsLeafExpression="x=>x.DataItem.Children ==null || !x.DataItem.Children.Any()"
                  DefaultExpandParent="true"
                  Style="height: 80Vh; overflow-y: scroll; min-width: 400px ">
            </Tree>
        </AntDesign.Col>
    </Row>
    <Row>
        <AntDesign.Col>
            <Space>
                <SpaceItem>
                    <Tooltip Placement="Placement.TopLeft" Title="@(_isExpanded?localizer["关闭"]:localizer["展开"])">
                        <Button Type="@ButtonType.Primary" Icon="@(_isExpanded?"up":"down")" Size="@ClientConstant.OperationButtonSize" OnClick="OnExpandClick" />
                    </Tooltip>
                </SpaceItem>
                <SpaceItem>
                    <ResourceAuthorize ResourceKey="user_center_role_set_resource_save">
                        <Space>
                            <SpaceItem>
                                <Button Type="@ButtonType.Primary" Size="@ClientConstant.OperationButtonSize" OnClick="OnSaveClick">
                                @localizer["保存"]
                                </Button>
                            </SpaceItem>
                            <SpaceItem>
                                <Button Type="@ButtonType.Default" Size="@ClientConstant.OperationButtonSize" OnClick="OnCancelClick">
                                    @localizer["取消"]
                                </Button>
                            </SpaceItem>
                        </Space>
                    </ResourceAuthorize>
                </SpaceItem>
            </Space>
        </AntDesign.Col>
    </Row>
</Spin>

@{
    string GetFullName(ResourceDto resource)
    {
        return "[" + resource.Type.GetEnumDescription() + "]" + resource.Name;
    }
}
